using System;
using AntEater.ComponentModel;
using AntEater.ComponentModel.Configuration;
using AntEater.Runtime.Services;
using AntEater.Runtime.UI;
using System.Windows.Forms;

namespace AntEater.Runtime
{
    /// <summary>
    /// The implementation of the AntEater Runtime.
    /// </summary>
    public class AntEaterRuntime : IAntEaterRuntime
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AntEaterRuntime"/> class.
        /// </summary>
        private AntEaterRuntime() {
            this._solution = new Solution();
            this._options = new Options();
            this._configuration = new AntEaterConfiguration();
            this._output = new Output();
            this._presenters = new PresenterProvider(new PresenterContext(this), _configuration.AntEater.Presenters);
            this._runtimeServices = new RuntimeServiceProvider(new RuntimeServiceContext(this._options, this._output), _configuration.AntEater.RuntimeServices);

            // Initailize Visual Style of Application 
            ToolStripProfessionalRenderer renderer = new ToolStripProfessionalRenderer();
            renderer.RoundedEdges = false;

            ToolStripManager.RenderMode = ToolStripManagerRenderMode.Professional;
            ToolStripManager.VisualStylesEnabled = true;
            ToolStripManager.Renderer = renderer;
        }

        private static AntEaterRuntime _instance;

        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <returns></returns>
        public static AntEaterRuntime Instance {
            get {
                if (_instance == null) {
                    _instance = new AntEaterRuntime();
                }
                return _instance;
            }
        }

        private Solution _solution;

        /// <summary>
        /// Gets the solution.
        /// </summary>
        /// <value>The solution.</value>
        public Solution Solution {
            get { return _solution; }
        }

        private Options _options;

        /// <summary>
        /// Gets the options.
        /// </summary>
        /// <value>The options.</value>
        public Options Options {
            get { return _options; }
        }

        private AntEaterConfiguration _configuration;

        /// <summary>
        /// Gets the configuration.
        /// </summary>
        /// <value>The configuration.</value>
        public AntEaterConfiguration Configuration {
            get { return _configuration; }
        }

        private Output _output;

        /// <summary>
        /// Gets the output.
        /// </summary>
        /// <value>The output.</value>
        public Output Output {
            get { return _output; }
        }

        private RuntimeServiceProvider _runtimeServices;

        /// <summary>
        /// Gets the runtime services.
        /// </summary>
        /// <value>The runtime services.</value>
        public RuntimeServiceProvider RuntimeServices {
            get { return _runtimeServices; }
        }

        private PresenterProvider _presenters;

        /// <summary>
        /// Gets the presenters.
        /// </summary>
        /// <value>The presenters.</value>
        public PresenterProvider Presenters {
            get { return _presenters; }
        }
    }
}
